﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentManage
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //获取用户输入信息
            string uName = txtUserName.Text.Trim();
            string uPwd = txtUserPwd.Text.Trim();
            //判断是否为空
            if (string.IsNullOrEmpty(uName))
            {
                MessageBox.Show("请输入账号！","登录提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                txtUserName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(uPwd))
            {
                MessageBox.Show("请输入密码！", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserPwd.Focus();
                return;
            }
            //与数据库通信，检查输入是否与数据库一致
            string sql = "select * from userinfo where UserName='" + uName + "' and UserPwd='" + uPwd + "'";
            //object obj = DBHelper.ExecuteScalar(sql,1);
            object obj = SqlHelper.ExecuteScalar(sql,1);
            //根据返回结果提示不同信息
            if (obj == null)
            {
                MessageBox.Show("登录账号或密码错误，请检查", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                MessageBox.Show("登陆成功", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //跳转到主页面
                FrmMain fMain = new FrmMain();
                fMain.Show();
                this.Hide();
            }            
        }
        //退出系统
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
            //Application.Exit();
        }
    }
}
